
	mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:false,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
	});
	
	
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var currenPage=1;
    var pageSize=10;
    var total_page=0;
    var total_count=0;
    
    window.onload = function(){
    	mui.ajax({
				url: apiurl + "Trade/receiptList/",
				data: {user_id:uid,'p':currenPage,'size':pageSize,'_token': userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					if(res.status == -3) {
						mui.toast(res.msg);
						app.out();
						return false;
					}
					// 请求成功
					if(!res.status) {
						//mui.toast(res.msg);
					} else {
						total_page=res.total_page;
						total_count=res.sum;
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll').append(htm);
						if(total_count==0){
							$('#pullrefresh .mui-scroll').append('<p style="text-align:center;margin-top:20px;">没有找到相关记录</p>');
						}
					}
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
			
			mui.plusReady(function(){
			    //关闭等待框
			    plus.nativeUI.closeWaiting();
			    //显示当前页面
			    mui.currentWebview.show();
			});
    }

    window.addEventListener('refresh_data',function(event){
		location.href=location;
	});
	
    function get_data(data){
    	var htm='';
		for(i in data) {
			/*
			 * <div class="completed_list">
					<div class="order_num"><span>订单号：15249045512706149</span><button>交易成功</button></div>
					<div class="list_info">
						<div class="info_l">
							<span>打款人：黄鹂</span>
							<span>打款银行：中国农业银行</span>
							<span>打款账号：6228451098014741176</span>
						</div>
						<div class="info_r">
							<span>500</span>
							<span class="info_r2">实付金额425RMB</span>
							<span>2018-04-29 16:33:11</span>
						</div>
					</div>
				</div>
			 */
			htm+='<div class="completed_list">';
			htm+='<div class="order_num"><span>订单号：'+data[i]['order_sn']+'</span><button onclick="do_receipt(\''+data[i]['id']+'\')">收款</button></div>';
			htm+='<div class="list_info" onclick="see_detail(\''+data[i]['id']+'\')">';
			htm+='<div class="info_l">';
			htm+='<span>打款人：'+data[i]['buy_bank_account']+'</span>';
			htm+='<span>打款银行：'+data[i]['buy_bank_name']+'</span>';
			htm+='<span>打款账号：'+data[i]['buy_bank_card']+'</span>';
			htm+='</div>';
			htm+='<div class="info_r">';
			htm+='<span>'+data[i]['trade_money']+'</span>';
			htm+='<span class="info_r2">实付金额'+data[i]['amount']+'RMB</span>';
			htm+='<span>'+data[i]['pay_time']+'</span>';
			htm += '</div>';
			htm += '</div>';
			htm += '</div>';
		}
		return htm;
    }

	var count = 0;
	function pullupRefresh() {
		setTimeout(function() {
			currenPage++;
			mui.ajax({
				url: apiurl + "Trade/receiptList/",
				data: {user_id:uid,'p':currenPage,'size':pageSize,'_token': userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					if(res.status == -3) {
						mui.toast(res.msg);
						app.out();
						return false;
					}
					
					// 请求成功
					if(!res.status) {
						//mui.toast(res.msg);
					} else {
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll').append(htm);
					}
					
					if(currenPage < total_page){
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    /*能上拉*/
	                }else{
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);/*不能上拉*/
	                }
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});

		}, 1500);
	}
	
	
	//看订单详情
    function see_detail(tid){
    	//打开卖出订单详情
		mui.openWindow({
			id: 'buyorder.html',
			url: 'buyorder.html',
			extras: {
				trade_id: tid //自定义扩展参数，可以用来处理页面间传值
			},
			show: {
				autoShow: false
			},
			waiting: {
				autoShow: true,
				title: '正在加载...'
			}
		});
    }
	

	//收款页
	function do_receipt(tid){
		//打开打款详情
		mui.openWindow({
			id: 'receipt_detail.html',
			url: 'receipt_detail.html',
			extras: {
				trade_id: tid //自定义扩展参数，可以用来处理页面间传值
			},
			show: {
				autoShow: false
			},
			waiting: {
				autoShow: true,
				title: '正在加载...'
			}
		});
	}